package com.lzy.huijinjiazu.mvp.ui.adapter;

import android.content.Context;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.utils.ArmsUtils;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.mvp.ui.activity.OrderDetailActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by long on 2018/1/13.
 */

public class OrderAdapter extends DefaultAdapter<String> {
    public OrderAdapter() {
        super(new ArrayList<>());
    }

    @Override
    public BaseHolder<String> getHolder(View v, int viewType) {
        return new OrderHolder(v);
    }

    public class OrderHolder extends BaseHolder<String> {
        @BindView(R.id.rv_child_list)
        RecyclerView mRvChildList;
        @BindView(R.id.tv_total)
        TextView mTvTotal;
        private OrderChildAdapter mGoodsAdapter;
        private List<String> mData = new ArrayList<>();
        private Context mContext;

        public OrderHolder(View itemView) {
            super(itemView);
            mContext = itemView.getContext();
            mRvChildList.setLayoutManager(new LinearLayoutManager(itemView.getContext()) {
                @Override
                public boolean canScrollVertically() {
                    return false;
                }
            });
            mRvChildList.addItemDecoration(new RecyclerView.ItemDecoration() {
                @Override
                public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                    outRect.top = ArmsUtils.dip2px(itemView.getContext(), 1);
                }
            });
            mGoodsAdapter = new OrderChildAdapter();
            for (int i = 0; i < 2; i++) {
                mData.add("");
            }
        }

        @Override
        public void setData(String data, int position) {
            mRvChildList.setAdapter(mGoodsAdapter);
            mGoodsAdapter.setNewData(mData);
            mTvTotal.setText(Html.fromHtml(ArmsUtils.getString(mContext, R.string.order_total_money, "2", "2000", "200")));
            itemView.setOnClickListener(view -> {
                ArmsUtils.startActivity(OrderDetailActivity.class);
            });
        }
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_order_list;
    }
}
